<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<jsp:include page="../inc.jsp"></jsp:include>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="${ctx}/css/common.css"/>
<style type="text/css">
	input{
		height:22px;
	}
	.only{
		margin-left:50px;
		margin-top:30px;
	}
	.bn{
		margin-top:60px;
		margin-left:100px;
	}
	.pass{
		width:70px;
		height:30px;
		line-height:30px;
		background:#f9a61a;
		border:none;
		border-radius: 3px;
		color:white;
	}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>提现 --小窗口</title>
<link rel="stylesheet" href="${ctx}/jslib/layui/css/layui.css" media="all">
<script type="text/javascript" src="${ctx}/jslib/layer/layer.js" charset="utf-8"></script>
</head>
<script type="text/javascript">
	//封装函数  实现强制转换成两位小数的功能
	onload = function(a){
	    var aNew;
	    var re = /([0-9]+.[0-9]{2})[0-9]*/;
	    aNew = a.replace(re,"$1");
	 	return aNew;
	};
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	function closeWin(){
		 parent.layer.close(index);
	};
	$(function(){
		$("#cancel").click(function(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		});
		$("#need").blur(function(){
			var need= $("#need").val();
			var a=onload(need);
			$("#need").val(a);//强制将超过3位小数的改为2位小数
			if(isNaN(need) || need == 0){
				layer.alert("金额请填入数字且不能为0");
			};
		});
		$("#sure").click(function(){
			
			var isValid = $('#dataForm').form('validate');
			if (!isValid) {
				progressClose();
				return;
			}
			
			var need= $("#need").val();
			if(need == 0){
				layer.alert("请输入具体提现金额!");
				return;
			}
			
			$.ajax({
				type:'post',
				url:'${ctx}/withdrawal/withdrawForBuyer?amount='+need,
				dataType:'json',
				success:function(data){
					if(data.success){
						layer.alert('提现申请已提交！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, 
								function(index){
							closeWin();
							layer.close(index);
						});
					}else{
						layer.alert(data.msg);
					}
				},
				error:function(msg){
					layer.alert("请检查您的网络连接，然后重试！");
				}
			}); 
			
			
		});
		
	});
</script>
<body>
	<div class="only">
		<form id="dataForm">
			提现金额：<input type="text" size="20" id="need"></input>
		</form>
	</div>
	<div class="bn">
		<input type="button" id="sure" value="确认" class="add_minus" style="float:left;"/>
		<input type="button" id="cancel" value="取消" class="backOne" style="margin-left:20px;float:left;"/>
	</div>
</body>
</html>